<?php
/**
 * 字典文件
 *
 * @author lwb
 */
namespace app\wechat\controller;

use app\wechat\model\City;
use app\wechat\model\BankCity;

class Dict extends Common {

    /**
     * 银行省
     */
    public static function BankProvince() {
        $bankcitys = BankCity::where('level', '省级')->field('province,area_code')->group('province')->order('area_code')->select();
        
        return objToArray($bankcitys);
    }
    
    /**
     * 银行市
     */
    public static function BankCity($id) {
        $bankcitys = BankCity::where('province', $id)->field('city,area_code')->group('city')->order('area_code')->select();
        
        return objToArray($bankcitys);
    }
    
    /**
     * 银行区
     */
    public static function BankArea($id) {
        $bankcitys = BankCity::where('city', $id)->field('area_code,area_name')->order('area_code')->select();
        
        return objToArray($bankcitys);
    }
    
    /*
     * 省
     */
    public static function provinceList(){
        $citys = City::where('city_pid', '8a8a8aee41beab700141beaf79d50002')->field('city_key,city_name')->select();
        
        return objToArray($citys);
    }
    
    /*
     * 市
     */
    public static function cityList($id){
        $city_id = City::where('city_key', $id)->value('city_id');
        $citys = City::where('city_pid', $city_id)->field('city_key,city_name')->select();
        if(!$citys){
            $citys = [
                [
                    'city_key' => $id,
                    'city_name' => City::where('city_id', $city_id)->value('city_name')
                ]
            ];
        }else{
            $citys = objToArray($citys);
        }
        
        return $citys;
    }

}
